package com.cat.dataStructure03;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/power-of-heroes/
 * @create 2025/11/8 17:11
 * @since JDK17
 */

class Solution24 {
    public int sumOfPower(int[] nums) {
        Arrays.sort(nums);
        long N = (int) 1e9 + 7, left = 0, ans = 0;
        for (long x : nums) {
            ans = (ans + ((x * x % N) * (x + left))) % N;
            left = (left * 2 + x) % N;
        }

        return (int)ans;
    }
}